import type { Router } from 'vue-router'

const routerConfig = (router: Router) => {
  router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token') || null
    if ((to.path === '/' || to.path === '/login') && token) {
      next('/app/index')
    }
    if (to.path.includes('/app') && !token) {
      next('/login')
    }
    next()
  })
}
export default routerConfig
